/*==============================================================*/
/* DBMS name:      Microsoft SQL Server 2008                    */
/* Created on:     2/25/2011 9:00:03 PM                         */
/*==============================================================*/


IF EXISTS ( SELECT  1
            FROM    sys.sysreferences r
                    JOIN sys.sysobjects o ON ( o.id = r.constid
                                               AND o.type = 'F'
                                             )
            WHERE   r.fkeyid = OBJECT_ID('GIAOHAT')
                    AND o.name = 'FK_GIAOHAT_RELATIONS_GIAOPHAN' ) 
    ALTER TABLE GIAOHAT
    DROP CONSTRAINT FK_GIAOHAT_RELATIONS_GIAOPHAN
go

IF EXISTS ( SELECT  1
            FROM    sys.sysreferences r
                    JOIN sys.sysobjects o ON ( o.id = r.constid
                                               AND o.type = 'F'
                                             )
            WHERE   r.fkeyid = OBJECT_ID('GIAOHAT')
                    AND o.name = 'FK_GIAOHAT_RELATIONS_LINHMUC' ) 
    ALTER TABLE GIAOHAT
    DROP CONSTRAINT FK_GIAOHAT_RELATIONS_LINHMUC
go

IF EXISTS ( SELECT  1
            FROM    sys.sysreferences r
                    JOIN sys.sysobjects o ON ( o.id = r.constid
                                               AND o.type = 'F'
                                             )
            WHERE   r.fkeyid = OBJECT_ID('GIAOHO')
                    AND o.name = 'FK_GIAOHO_RELATIONS_GIAOXU' ) 
    ALTER TABLE GIAOHO
    DROP CONSTRAINT FK_GIAOHO_RELATIONS_GIAOXU
go

IF EXISTS ( SELECT  1
            FROM    sys.sysreferences r
                    JOIN sys.sysobjects o ON ( o.id = r.constid
                                               AND o.type = 'F'
                                             )
            WHERE   r.fkeyid = OBJECT_ID('GIAOPHAN')
                    AND o.name = 'FK_GIAOPHAN_RELATIONS_LINHMUC' ) 
    ALTER TABLE GIAOPHAN
    DROP CONSTRAINT FK_GIAOPHAN_RELATIONS_LINHMUC
go

IF EXISTS ( SELECT  1
            FROM    sys.sysreferences r
                    JOIN sys.sysobjects o ON ( o.id = r.constid
                                               AND o.type = 'F'
                                             )
            WHERE   r.fkeyid = OBJECT_ID('GIAOXU')
                    AND o.name = 'FK_GIAOXU_RELATIONS_LINHMUC' ) 
    ALTER TABLE GIAOXU
    DROP CONSTRAINT FK_GIAOXU_RELATIONS_LINHMUC
go

IF EXISTS ( SELECT  1
            FROM    sys.sysreferences r
                    JOIN sys.sysobjects o ON ( o.id = r.constid
                                               AND o.type = 'F'
                                             )
            WHERE   r.fkeyid = OBJECT_ID('GIAOXU')
                    AND o.name = 'FK_GIAOXU_RELATIONS_GIAOHAT' ) 
    ALTER TABLE GIAOXU
    DROP CONSTRAINT FK_GIAOXU_RELATIONS_GIAOHAT
go

IF EXISTS ( SELECT  1
            FROM    sys.sysreferences r
                    JOIN sys.sysobjects o ON ( o.id = r.constid
                                               AND o.type = 'F'
                                             )
            WHERE   r.fkeyid = OBJECT_ID('HOGIADINH')
                    AND o.name = 'FK_HOGIADIN_RELATIONS_QUOCGIA' ) 
    ALTER TABLE HOGIADINH
    DROP CONSTRAINT FK_HOGIADIN_RELATIONS_QUOCGIA
go

IF EXISTS ( SELECT  1
            FROM    sys.sysreferences r
                    JOIN sys.sysobjects o ON ( o.id = r.constid
                                               AND o.type = 'F'
                                             )
            WHERE   r.fkeyid = OBJECT_ID('HOGIADINH')
                    AND o.name = 'FK_HOGIADIN_RELATIONS_TINHTHAN' ) 
    ALTER TABLE HOGIADINH
    DROP CONSTRAINT FK_HOGIADIN_RELATIONS_TINHTHAN
go

IF EXISTS ( SELECT  1
            FROM    sys.sysreferences r
                    JOIN sys.sysobjects o ON ( o.id = r.constid
                                               AND o.type = 'F'
                                             )
            WHERE   r.fkeyid = OBJECT_ID('HOGIADINH')
                    AND o.name = 'FK_HOGIADIN_RELATIONS_QUANHUYE' ) 
    ALTER TABLE HOGIADINH
    DROP CONSTRAINT FK_HOGIADIN_RELATIONS_QUANHUYE
go

IF EXISTS ( SELECT  1
            FROM    sys.sysreferences r
                    JOIN sys.sysobjects o ON ( o.id = r.constid
                                               AND o.type = 'F'
                                             )
            WHERE   r.fkeyid = OBJECT_ID('HOGIADINH')
                    AND o.name = 'FK_HOGIADIN_RELATIONS_XAPHUONG' ) 
    ALTER TABLE HOGIADINH
    DROP CONSTRAINT FK_HOGIADIN_RELATIONS_XAPHUONG
go

IF EXISTS ( SELECT  1
            FROM    sys.sysreferences r
                    JOIN sys.sysobjects o ON ( o.id = r.constid
                                               AND o.type = 'F'
                                             )
            WHERE   r.fkeyid = OBJECT_ID('HOGIADINH')
                    AND o.name = 'FK_HOGIADIN_RELATIONS_GIAOHO' ) 
    ALTER TABLE HOGIADINH
    DROP CONSTRAINT FK_HOGIADIN_RELATIONS_GIAOHO
go

IF EXISTS ( SELECT  1
            FROM    sys.sysreferences r
                    JOIN sys.sysobjects o ON ( o.id = r.constid
                                               AND o.type = 'F'
                                             )
            WHERE   r.fkeyid = OBJECT_ID('HOGIADINH_GIAODAN')
                    AND o.name = 'FK_HOGIADIN_RELATIONS_QUANHEGI' ) 
    ALTER TABLE HOGIADINH_GIAODAN
    DROP CONSTRAINT FK_HOGIADIN_RELATIONS_QUANHEGI
go

IF EXISTS ( SELECT  1
            FROM    sys.sysreferences r
                    JOIN sys.sysobjects o ON ( o.id = r.constid
                                               AND o.type = 'F'
                                             )
            WHERE   r.fkeyid = OBJECT_ID('HOGIADINH_GIAODAN')
                    AND o.name = 'FK_HOGIADIN_RELATIONS_HOGIADIN' ) 
    ALTER TABLE HOGIADINH_GIAODAN
    DROP CONSTRAINT FK_HOGIADIN_RELATIONS_HOGIADIN
go

IF EXISTS ( SELECT  1
            FROM    sys.sysreferences r
                    JOIN sys.sysobjects o ON ( o.id = r.constid
                                               AND o.type = 'F'
                                             )
            WHERE   r.fkeyid = OBJECT_ID('HOGIADINH_GIAODAN')
                    AND o.name = 'FK_HOGIADIN_RELATIONS_GIAODAN' ) 
    ALTER TABLE HOGIADINH_GIAODAN
    DROP CONSTRAINT FK_HOGIADIN_RELATIONS_GIAODAN
go

IF EXISTS ( SELECT  1
            FROM    sys.sysreferences r
                    JOIN sys.sysobjects o ON ( o.id = r.constid
                                               AND o.type = 'F'
                                             )
            WHERE   r.fkeyid = OBJECT_ID('QUANHUYEN')
                    AND o.name = 'FK_QUANHUYE_RELATIONS_TINHTHAN' ) 
    ALTER TABLE QUANHUYEN
    DROP CONSTRAINT FK_QUANHUYE_RELATIONS_TINHTHAN
go

IF EXISTS ( SELECT  1
            FROM    sys.sysreferences r
                    JOIN sys.sysobjects o ON ( o.id = r.constid
                                               AND o.type = 'F'
                                             )
            WHERE   r.fkeyid = OBJECT_ID('TINHTHANH')
                    AND o.name = 'FK_TINHTHAN_RELATIONS_QUOCGIA' ) 
    ALTER TABLE TINHTHANH
    DROP CONSTRAINT FK_TINHTHAN_RELATIONS_QUOCGIA
go

IF EXISTS ( SELECT  1
            FROM    sys.sysreferences r
                    JOIN sys.sysobjects o ON ( o.id = r.constid
                                               AND o.type = 'F'
                                             )
            WHERE   r.fkeyid = OBJECT_ID('XAPHUONG')
                    AND o.name = 'FK_XAPHUONG_RELATIONS_QUANHUYE' ) 
    ALTER TABLE XAPHUONG
    DROP CONSTRAINT FK_XAPHUONG_RELATIONS_QUANHUYE
go

IF EXISTS ( SELECT  1
            FROM    sysobjects
            WHERE   id = OBJECT_ID('GHICHU')
                    AND type = 'U' ) 
    DROP TABLE GHICHU
go

IF EXISTS ( SELECT  1
            FROM    sysobjects
            WHERE   id = OBJECT_ID('GIAODAN')
                    AND type = 'U' ) 
    DROP TABLE GIAODAN
go

IF EXISTS ( SELECT  1
            FROM    sysindexes
            WHERE   id = OBJECT_ID('GIAOHAT')
                    AND name = 'RELATIONSHIP_16_FK'
                    AND indid > 0
                    AND indid < 255 ) 
    DROP INDEX GIAOHAT.RELATIONSHIP_16_FK
go

IF EXISTS ( SELECT  1
            FROM    sysindexes
            WHERE   id = OBJECT_ID('GIAOHAT')
                    AND name = 'RELATIONSHIP_1_FK'
                    AND indid > 0
                    AND indid < 255 ) 
    DROP INDEX GIAOHAT.RELATIONSHIP_1_FK
go

IF EXISTS ( SELECT  1
            FROM    sysobjects
            WHERE   id = OBJECT_ID('GIAOHAT')
                    AND type = 'U' ) 
    DROP TABLE GIAOHAT
go

IF EXISTS ( SELECT  1
            FROM    sysindexes
            WHERE   id = OBJECT_ID('GIAOHO')
                    AND name = 'RELATIONSHIP_3_FK'
                    AND indid > 0
                    AND indid < 255 ) 
    DROP INDEX GIAOHO.RELATIONSHIP_3_FK
go

IF EXISTS ( SELECT  1
            FROM    sysobjects
            WHERE   id = OBJECT_ID('GIAOHO')
                    AND type = 'U' ) 
    DROP TABLE GIAOHO
go

IF EXISTS ( SELECT  1
            FROM    sysindexes
            WHERE   id = OBJECT_ID('GIAOPHAN')
                    AND name = 'RELATIONSHIP_15_FK'
                    AND indid > 0
                    AND indid < 255 ) 
    DROP INDEX GIAOPHAN.RELATIONSHIP_15_FK
go

IF EXISTS ( SELECT  1
            FROM    sysobjects
            WHERE   id = OBJECT_ID('GIAOPHAN')
                    AND type = 'U' ) 
    DROP TABLE GIAOPHAN
go

IF EXISTS ( SELECT  1
            FROM    sysindexes
            WHERE   id = OBJECT_ID('GIAOXU')
                    AND name = 'RELATIONSHIP_17_FK'
                    AND indid > 0
                    AND indid < 255 ) 
    DROP INDEX GIAOXU.RELATIONSHIP_17_FK
go

IF EXISTS ( SELECT  1
            FROM    sysindexes
            WHERE   id = OBJECT_ID('GIAOXU')
                    AND name = 'RELATIONSHIP_2_FK'
                    AND indid > 0
                    AND indid < 255 ) 
    DROP INDEX GIAOXU.RELATIONSHIP_2_FK
go

IF EXISTS ( SELECT  1
            FROM    sysobjects
            WHERE   id = OBJECT_ID('GIAOXU')
                    AND type = 'U' ) 
    DROP TABLE GIAOXU
go

IF EXISTS ( SELECT  1
            FROM    sysindexes
            WHERE   id = OBJECT_ID('HOGIADINH')
                    AND name = 'RELATIONSHIP_14_FK'
                    AND indid > 0
                    AND indid < 255 ) 
    DROP INDEX HOGIADINH.RELATIONSHIP_14_FK
go

IF EXISTS ( SELECT  1
            FROM    sysindexes
            WHERE   id = OBJECT_ID('HOGIADINH')
                    AND name = 'RELATIONSHIP_13_FK'
                    AND indid > 0
                    AND indid < 255 ) 
    DROP INDEX HOGIADINH.RELATIONSHIP_13_FK
go

IF EXISTS ( SELECT  1
            FROM    sysindexes
            WHERE   id = OBJECT_ID('HOGIADINH')
                    AND name = 'RELATIONSHIP_12_FK'
                    AND indid > 0
                    AND indid < 255 ) 
    DROP INDEX HOGIADINH.RELATIONSHIP_12_FK
go

IF EXISTS ( SELECT  1
            FROM    sysindexes
            WHERE   id = OBJECT_ID('HOGIADINH')
                    AND name = 'RELATIONSHIP_11_FK'
                    AND indid > 0
                    AND indid < 255 ) 
    DROP INDEX HOGIADINH.RELATIONSHIP_11_FK
go

IF EXISTS ( SELECT  1
            FROM    sysindexes
            WHERE   id = OBJECT_ID('HOGIADINH')
                    AND name = 'RELATIONSHIP_4_FK'
                    AND indid > 0
                    AND indid < 255 ) 
    DROP INDEX HOGIADINH.RELATIONSHIP_4_FK
go

IF EXISTS ( SELECT  1
            FROM    sysobjects
            WHERE   id = OBJECT_ID('HOGIADINH')
                    AND type = 'U' ) 
    DROP TABLE HOGIADINH
go

IF EXISTS ( SELECT  1
            FROM    sysindexes
            WHERE   id = OBJECT_ID('HOGIADINH_GIAODAN')
                    AND name = 'RELATIONSHIP_10_FK'
                    AND indid > 0
                    AND indid < 255 ) 
    DROP INDEX HOGIADINH_GIAODAN.RELATIONSHIP_10_FK
go

IF EXISTS ( SELECT  1
            FROM    sysindexes
            WHERE   id = OBJECT_ID('HOGIADINH_GIAODAN')
                    AND name = 'RELATIONSHIP_9_FK'
                    AND indid > 0
                    AND indid < 255 ) 
    DROP INDEX HOGIADINH_GIAODAN.RELATIONSHIP_9_FK
go

IF EXISTS ( SELECT  1
            FROM    sysindexes
            WHERE   id = OBJECT_ID('HOGIADINH_GIAODAN')
                    AND name = 'RELATIONSHIP_8_FK'
                    AND indid > 0
                    AND indid < 255 ) 
    DROP INDEX HOGIADINH_GIAODAN.RELATIONSHIP_8_FK
go

IF EXISTS ( SELECT  1
            FROM    sysobjects
            WHERE   id = OBJECT_ID('HOGIADINH_GIAODAN')
                    AND type = 'U' ) 
    DROP TABLE HOGIADINH_GIAODAN
go

IF EXISTS ( SELECT  1
            FROM    sysobjects
            WHERE   id = OBJECT_ID('LINHMUC')
                    AND type = 'U' ) 
    DROP TABLE LINHMUC
go

IF EXISTS ( SELECT  1
            FROM    sysobjects
            WHERE   id = OBJECT_ID('QUANHEGIATOC')
                    AND type = 'U' ) 
    DROP TABLE QUANHEGIATOC
go

IF EXISTS ( SELECT  1
            FROM    sysindexes
            WHERE   id = OBJECT_ID('QUANHUYEN')
                    AND name = 'RELATIONSHIP_6_FK'
                    AND indid > 0
                    AND indid < 255 ) 
    DROP INDEX QUANHUYEN.RELATIONSHIP_6_FK
go

IF EXISTS ( SELECT  1
            FROM    sysobjects
            WHERE   id = OBJECT_ID('QUANHUYEN')
                    AND type = 'U' ) 
    DROP TABLE QUANHUYEN
go

IF EXISTS ( SELECT  1
            FROM    sysobjects
            WHERE   id = OBJECT_ID('QUOCGIA')
                    AND type = 'U' ) 
    DROP TABLE QUOCGIA
go

IF EXISTS ( SELECT  1
            FROM    sysindexes
            WHERE   id = OBJECT_ID('TINHTHANH')
                    AND name = 'RELATIONSHIP_5_FK'
                    AND indid > 0
                    AND indid < 255 ) 
    DROP INDEX TINHTHANH.RELATIONSHIP_5_FK
go

IF EXISTS ( SELECT  1
            FROM    sysobjects
            WHERE   id = OBJECT_ID('TINHTHANH')
                    AND type = 'U' ) 
    DROP TABLE TINHTHANH
go

IF EXISTS ( SELECT  1
            FROM    sysindexes
            WHERE   id = OBJECT_ID('XAPHUONG')
                    AND name = 'RELATIONSHIP_7_FK'
                    AND indid > 0
                    AND indid < 255 ) 
    DROP INDEX XAPHUONG.RELATIONSHIP_7_FK
go

IF EXISTS ( SELECT  1
            FROM    sysobjects
            WHERE   id = OBJECT_ID('XAPHUONG')
                    AND type = 'U' ) 
    DROP TABLE XAPHUONG
go

/*==============================================================*/
/* Table: GHICHU                                                */
/*==============================================================*/
CREATE TABLE GHICHU
    (
      MAGHICHU UNIQUEIDENTIFIER ROWGUIDCOL
                                NOT NULL ,
      MANGUON NVARCHAR(100) NULL ,
      TENGHICHU NVARCHAR(100) NULL ,
      NOIDUNG NVARCHAR(2000) NULL ,
      NGAYTAO DATETIME NULL ,
      NGAYCHINHSUA DATETIME NULL ,
      CONSTRAINT PK_GHICHU PRIMARY KEY NONCLUSTERED ( MAGHICHU )
    )
go

/*==============================================================*/
/* Table: GIAODAN                                               */
/*==============================================================*/
CREATE TABLE GIAODAN
    (
      MAGIAODAN UNIQUEIDENTIFIER ROWGUIDCOL
                                 NOT NULL
                                 DEFAULT ( NEWID() ) ,
      TENTHANH NVARCHAR(500) NULL ,
      HOVATENDEM NVARCHAR(500) NULL ,
      TEN NVARCHAR(100) NULL ,
      NGAYSINH NVARCHAR(2) NULL ,
      THANGSINH NVARCHAR(2) NULL ,
      NAMSINH NVARCHAR(4) NULL ,
      DIENTHOAI NVARCHAR(20) NULL ,
      CONSTRAINT PK_GIAODAN PRIMARY KEY NONCLUSTERED ( MAGIAODAN )
    )
go

/*==============================================================*/
/* Table: GIAOHAT                                               */
/*==============================================================*/
CREATE TABLE GIAOHAT
    (
      MAGIAOHAT UNIQUEIDENTIFIER ROWGUIDCOL
                                 NOT NULL
                                 DEFAULT ( NEWID() ) ,
      MACHAXU UNIQUEIDENTIFIER NULL ,
      MAGIAOPHAN UNIQUEIDENTIFIER NULL ,
      TENGIAOHAT NVARCHAR(1000) NULL ,
      DIACHI NVARCHAR(1000) NULL ,
      DIENTHOAI NVARCHAR(20) NULL ,
      CONSTRAINT PK_GIAOHAT PRIMARY KEY NONCLUSTERED ( MAGIAOHAT )
    )
go

/*==============================================================*/
/* Index: RELATIONSHIP_1_FK                                     */
/*==============================================================*/
CREATE INDEX RELATIONSHIP_1_FK ON GIAOHAT (
MAGIAOPHAN ASC
)
go

/*==============================================================*/
/* Index: RELATIONSHIP_16_FK                                    */
/*==============================================================*/
CREATE INDEX RELATIONSHIP_16_FK ON GIAOHAT (
MACHAXU ASC
)
go

/*==============================================================*/
/* Table: GIAOHO                                                */
/*==============================================================*/
CREATE TABLE GIAOHO
    (
      MAGIAOHO UNIQUEIDENTIFIER ROWGUIDCOL
                                NOT NULL
                                DEFAULT ( NEWID() ) ,
      MAGIAOXU UNIQUEIDENTIFIER NULL ,
      TENGIAOHO NVARCHAR(1000) NULL ,
      DIENTHOAI NVARCHAR(20) NULL ,
      CONSTRAINT PK_GIAOHO PRIMARY KEY NONCLUSTERED ( MAGIAOHO )
    )
go

/*==============================================================*/
/* Index: RELATIONSHIP_3_FK                                     */
/*==============================================================*/
CREATE INDEX RELATIONSHIP_3_FK ON GIAOHO (
MAGIAOXU ASC
)
go

/*==============================================================*/
/* Table: GIAOPHAN                                              */
/*==============================================================*/
CREATE TABLE GIAOPHAN
    (
      MAGIAOPHAN UNIQUEIDENTIFIER ROWGUIDCOL
                                  NOT NULL
                                  DEFAULT ( NEWID() ) ,
      MACHAXU UNIQUEIDENTIFIER NULL ,
      TENGIAOPHAN NVARCHAR(1000) NULL ,
      DIACHI NVARCHAR(1000) NULL ,
      DIENTHOAI NVARCHAR(20) NULL ,
      CONSTRAINT PK_GIAOPHAN PRIMARY KEY NONCLUSTERED ( MAGIAOPHAN )
    )
go

/*==============================================================*/
/* Index: RELATIONSHIP_15_FK                                    */
/*==============================================================*/
CREATE INDEX RELATIONSHIP_15_FK ON GIAOPHAN (
MACHAXU ASC
)
go

/*==============================================================*/
/* Table: GIAOXU                                                */
/*==============================================================*/
CREATE TABLE GIAOXU
    (
      MAGIAOXU UNIQUEIDENTIFIER ROWGUIDCOL
                                NOT NULL
                                DEFAULT ( NEWID() ) ,
      MACHAXU UNIQUEIDENTIFIER NULL ,
      MAGIAOHAT UNIQUEIDENTIFIER NULL ,
      TENGIAOXU NVARCHAR(1000) NULL ,
      DIACHI NVARCHAR(1000) NULL ,
      DIENTHOAI NVARCHAR(20) NULL ,
      CONSTRAINT PK_GIAOXU PRIMARY KEY NONCLUSTERED ( MAGIAOXU )
    )
go

/*==============================================================*/
/* Index: RELATIONSHIP_2_FK                                     */
/*==============================================================*/
CREATE INDEX RELATIONSHIP_2_FK ON GIAOXU (
MAGIAOHAT ASC
)
go

/*==============================================================*/
/* Index: RELATIONSHIP_17_FK                                    */
/*==============================================================*/
CREATE INDEX RELATIONSHIP_17_FK ON GIAOXU (
MACHAXU ASC
)
go

/*==============================================================*/
/* Table: HOGIADINH                                             */
/*==============================================================*/
CREATE TABLE HOGIADINH
    (
      MAHOGIADINH UNIQUEIDENTIFIER ROWGUIDCOL
                                   NOT NULL
                                   DEFAULT ( NEWID() ) ,
      MAGIAOHO UNIQUEIDENTIFIER NULL ,
      MAXAPHUONG UNIQUEIDENTIFIER NULL ,
      MAQUOCGIA UNIQUEIDENTIFIER NULL ,
      MAQUANHUYEN UNIQUEIDENTIFIER NULL ,
      MATINHTHANH UNIQUEIDENTIFIER NULL ,
      MAHO NVARCHAR(100) NULL ,
      DIENTHOAI NVARCHAR(20) NULL ,
      DIACHI NVARCHAR(1000) NULL ,
      CONSTRAINT PK_HOGIADINH PRIMARY KEY NONCLUSTERED ( MAHOGIADINH )
    )
go

/*==============================================================*/
/* Index: RELATIONSHIP_4_FK                                     */
/*==============================================================*/
CREATE INDEX RELATIONSHIP_4_FK ON HOGIADINH (
MAGIAOHO ASC
)
go

/*==============================================================*/
/* Index: RELATIONSHIP_11_FK                                    */
/*==============================================================*/
CREATE INDEX RELATIONSHIP_11_FK ON HOGIADINH (
MAQUOCGIA ASC
)
go

/*==============================================================*/
/* Index: RELATIONSHIP_12_FK                                    */
/*==============================================================*/
CREATE INDEX RELATIONSHIP_12_FK ON HOGIADINH (
MATINHTHANH ASC
)
go

/*==============================================================*/
/* Index: RELATIONSHIP_13_FK                                    */
/*==============================================================*/
CREATE INDEX RELATIONSHIP_13_FK ON HOGIADINH (
MAQUANHUYEN ASC
)
go

/*==============================================================*/
/* Index: RELATIONSHIP_14_FK                                    */
/*==============================================================*/
CREATE INDEX RELATIONSHIP_14_FK ON HOGIADINH (
MAXAPHUONG ASC
)
go

/*==============================================================*/
/* Table: HOGIADINH_GIAODAN                                     */
/*==============================================================*/
CREATE TABLE HOGIADINH_GIAODAN
    (
      MAGIAODAN UNIQUEIDENTIFIER NULL ,
      MAQUANHEGIATOC UNIQUEIDENTIFIER NULL ,
      MAHOGIADINH UNIQUEIDENTIFIER NULL ,
      THOIGIANBATDAU DATETIME NULL ,
      THOIGIANKETTHUC DATETIME NULL ,
      CHUHO BIT NULL
    )
go

/*==============================================================*/
/* Index: RELATIONSHIP_8_FK                                     */
/*==============================================================*/
CREATE INDEX RELATIONSHIP_8_FK ON HOGIADINH_GIAODAN (
MAHOGIADINH ASC
)
go

/*==============================================================*/
/* Index: RELATIONSHIP_9_FK                                     */
/*==============================================================*/
CREATE INDEX RELATIONSHIP_9_FK ON HOGIADINH_GIAODAN (
MAGIAODAN ASC
)
go

/*==============================================================*/
/* Index: RELATIONSHIP_10_FK                                    */
/*==============================================================*/
CREATE INDEX RELATIONSHIP_10_FK ON HOGIADINH_GIAODAN (
MAQUANHEGIATOC ASC
)
go

/*==============================================================*/
/* Table: LINHMUC                                               */
/*==============================================================*/
CREATE TABLE LINHMUC
    (
      MACHAXU UNIQUEIDENTIFIER ROWGUIDCOL
                               NOT NULL
                               DEFAULT ( NEWID() ) ,
      TENTHANH NVARCHAR(500) NULL ,
      HOVATENDEM NVARCHAR(500) NULL ,
      TEN NVARCHAR(100) NULL ,
      NGAYSINH NVARCHAR(2) NULL ,
      THANGSINH NVARCHAR(2) NULL ,
      NAMSINH NVARCHAR(4) NULL ,
      DIENTHOAI NVARCHAR(20) NULL ,
      CONSTRAINT PK_LINHMUC PRIMARY KEY NONCLUSTERED ( MACHAXU )
    )
go

/*==============================================================*/
/* Table: QUANHEGIATOC                                          */
/*==============================================================*/
CREATE TABLE QUANHEGIATOC
    (
      MAQUANHEGIATOC UNIQUEIDENTIFIER ROWGUIDCOL
                                      NOT NULL
                                      DEFAULT ( NEWID() ) ,
      TENQUANHEGIATOC NVARCHAR(500) NULL ,
      CONSTRAINT PK_QUANHEGIATOC PRIMARY KEY NONCLUSTERED ( MAQUANHEGIATOC )
    )
go

/*==============================================================*/
/* Table: QUANHUYEN                                             */
/*==============================================================*/
CREATE TABLE QUANHUYEN
    (
      MAQUANHUYEN UNIQUEIDENTIFIER ROWGUIDCOL
                                   NOT NULL
                                   DEFAULT ( NEWID() ) ,
      MATINHTHANH UNIQUEIDENTIFIER NULL ,
      TENQUANHUYEN NVARCHAR(1000) NULL ,
      CONSTRAINT PK_QUANHUYEN PRIMARY KEY NONCLUSTERED ( MAQUANHUYEN )
    )
go

/*==============================================================*/
/* Index: RELATIONSHIP_6_FK                                     */
/*==============================================================*/
CREATE INDEX RELATIONSHIP_6_FK ON QUANHUYEN (
MATINHTHANH ASC
)
go

/*==============================================================*/
/* Table: QUOCGIA                                               */
/*==============================================================*/
CREATE TABLE QUOCGIA
    (
      MAQUOCGIA UNIQUEIDENTIFIER ROWGUIDCOL
                                 NOT NULL
                                 DEFAULT ( NEWID() ) ,
      TENQUOCGIA NVARCHAR(1000) NULL ,
      VIETTAT NVARCHAR(100) NULL ,
      MABUUCHINH NVARCHAR(100) NULL ,
      CONSTRAINT PK_QUOCGIA PRIMARY KEY NONCLUSTERED ( MAQUOCGIA )
    )
go

/*==============================================================*/
/* Table: TINHTHANH                                             */
/*==============================================================*/
CREATE TABLE TINHTHANH
    (
      MATINHTHANH UNIQUEIDENTIFIER ROWGUIDCOL
                                   NOT NULL
                                   DEFAULT ( NEWID() ) ,
      MAQUOCGIA UNIQUEIDENTIFIER NULL ,
      TENTINHTHANH NVARCHAR(1000) NULL ,
      MABUUCHINH NVARCHAR(100) NULL ,
      CONSTRAINT PK_TINHTHANH PRIMARY KEY NONCLUSTERED ( MATINHTHANH )
    )
go

/*==============================================================*/
/* Index: RELATIONSHIP_5_FK                                     */
/*==============================================================*/
CREATE INDEX RELATIONSHIP_5_FK ON TINHTHANH (
MAQUOCGIA ASC
)
go

/*==============================================================*/
/* Table: XAPHUONG                                              */
/*==============================================================*/
CREATE TABLE XAPHUONG
    (
      MAXAPHUONG UNIQUEIDENTIFIER ROWGUIDCOL
                                  NOT NULL
                                  DEFAULT ( NEWID() ) ,
      MAQUANHUYEN UNIQUEIDENTIFIER NULL ,
      TENXAPHUONG NVARCHAR(1000) NULL ,
      CONSTRAINT PK_XAPHUONG PRIMARY KEY NONCLUSTERED ( MAXAPHUONG )
    )
go

/*==============================================================*/
/* Index: RELATIONSHIP_7_FK                                     */
/*==============================================================*/
CREATE INDEX RELATIONSHIP_7_FK ON XAPHUONG (
MAQUANHUYEN ASC
)
go

ALTER TABLE GIAOHAT
ADD CONSTRAINT FK_GIAOHAT_RELATIONS_GIAOPHAN FOREIGN KEY (MAGIAOPHAN)
REFERENCES GIAOPHAN (MAGIAOPHAN)
go

ALTER TABLE GIAOHAT
ADD CONSTRAINT FK_GIAOHAT_RELATIONS_LINHMUC FOREIGN KEY (MACHAXU)
REFERENCES LINHMUC (MACHAXU)
go

ALTER TABLE GIAOHO
ADD CONSTRAINT FK_GIAOHO_RELATIONS_GIAOXU FOREIGN KEY (MAGIAOXU)
REFERENCES GIAOXU (MAGIAOXU)
go

ALTER TABLE GIAOPHAN
ADD CONSTRAINT FK_GIAOPHAN_RELATIONS_LINHMUC FOREIGN KEY (MACHAXU)
REFERENCES LINHMUC (MACHAXU)
go

ALTER TABLE GIAOXU
ADD CONSTRAINT FK_GIAOXU_RELATIONS_LINHMUC FOREIGN KEY (MACHAXU)
REFERENCES LINHMUC (MACHAXU)
go

ALTER TABLE GIAOXU
ADD CONSTRAINT FK_GIAOXU_RELATIONS_GIAOHAT FOREIGN KEY (MAGIAOHAT)
REFERENCES GIAOHAT (MAGIAOHAT)
go

ALTER TABLE HOGIADINH
ADD CONSTRAINT FK_HOGIADIN_RELATIONS_QUOCGIA FOREIGN KEY (MAQUOCGIA)
REFERENCES QUOCGIA (MAQUOCGIA)
go

ALTER TABLE HOGIADINH
ADD CONSTRAINT FK_HOGIADIN_RELATIONS_TINHTHAN FOREIGN KEY (MATINHTHANH)
REFERENCES TINHTHANH (MATINHTHANH)
go

ALTER TABLE HOGIADINH
ADD CONSTRAINT FK_HOGIADIN_RELATIONS_QUANHUYE FOREIGN KEY (MAQUANHUYEN)
REFERENCES QUANHUYEN (MAQUANHUYEN)
go

ALTER TABLE HOGIADINH
ADD CONSTRAINT FK_HOGIADIN_RELATIONS_XAPHUONG FOREIGN KEY (MAXAPHUONG)
REFERENCES XAPHUONG (MAXAPHUONG)
go

ALTER TABLE HOGIADINH
ADD CONSTRAINT FK_HOGIADIN_RELATIONS_GIAOHO FOREIGN KEY (MAGIAOHO)
REFERENCES GIAOHO (MAGIAOHO)
go

ALTER TABLE HOGIADINH_GIAODAN
ADD CONSTRAINT FK_HOGIADIN_RELATIONS_QUANHEGI FOREIGN KEY (MAQUANHEGIATOC)
REFERENCES QUANHEGIATOC (MAQUANHEGIATOC)
go

ALTER TABLE HOGIADINH_GIAODAN
ADD CONSTRAINT FK_HOGIADIN_RELATIONS_HOGIADIN FOREIGN KEY (MAHOGIADINH)
REFERENCES HOGIADINH (MAHOGIADINH)
go

ALTER TABLE HOGIADINH_GIAODAN
ADD CONSTRAINT FK_HOGIADIN_RELATIONS_GIAODAN FOREIGN KEY (MAGIAODAN)
REFERENCES GIAODAN (MAGIAODAN)
go

ALTER TABLE QUANHUYEN
ADD CONSTRAINT FK_QUANHUYE_RELATIONS_TINHTHAN FOREIGN KEY (MATINHTHANH)
REFERENCES TINHTHANH (MATINHTHANH)
go

ALTER TABLE TINHTHANH
ADD CONSTRAINT FK_TINHTHAN_RELATIONS_QUOCGIA FOREIGN KEY (MAQUOCGIA)
REFERENCES QUOCGIA (MAQUOCGIA)
go

ALTER TABLE XAPHUONG
ADD CONSTRAINT FK_XAPHUONG_RELATIONS_QUANHUYE FOREIGN KEY (MAQUANHUYEN)
REFERENCES QUANHUYEN (MAQUANHUYEN)
go

